<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="renderer" content="webkit">
  <meta name="format-detection" content="telephone=no, email=no" />
  <script src="https://cdn.bootcss.com/vue/2.5.21/vue.js"></script>
  <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css"
        integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <link href="https://cdn.bootcss.com/notie/4.3.1/notie.min.css" rel="stylesheet">
  <script src="https://cdn.bootcss.com/notie/4.3.1/notie.min.js"></script>
  <script src="../sdk.dev.js"></script>
  <title>文件</title>
  <style>
    .card {
      margin-bottom: 20px;
    }
    .btn {
      margin-bottom: 5px;
    }
    .opt-btn {
      width: 24px;
      padding: 0;
      text-align: center;
    }
    .list-group {
      max-height: 200px;
      overflow-y: auto;
    }
    ul.category {
      display: flex;
      list-style: none;
      margin-bottom: 20px;
      padding-left: 0;
      overflow-x: auto;
    }
    .category li {
      display: inline;
      white-space: nowrap;
    }
    .category a {
      color: inherit;
      padding: 0 5px;
    }
    .category a.active {
      color: #007bff;
    }
    .upload-btn {
      position: relative;
      display: inline-block;
    }
    .upload-input {
      opacity: 0;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      cursor: pointer;
    }
  </style>
</head>
<body>
<div id="root" class="container">
  <nav aria-label="breadcrumb">
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="/">Home</a></li>
      <li class="breadcrumb-item active" aria-current="page">文件测试</li>
    </ol>
  </nav>

  <div class="card">
    <div class="card-body">
      <p>分类列表</p>
      <hr />
      <span>limit:</span>
      <div style="margin-bottom: 10px;">
        <button type="button" class="btn btn-primary opt-btn" @click="handleModifyNum('cateLimit', -1)">-</button>
        <span class="num">{{cateLimit}}</span>
        <button type="button" class="btn btn-primary opt-btn" @click="handleModifyNum('cateLimit', 1)">+</button>
      </div>
      <span>offset:</span>
      <div style="margin-bottom: 10px;">
        <button type="button" class="btn btn-primary opt-btn" @click="handleModifyNum('cateOffset', -1)">-</button>
        <span class="num">{{cateOffset}}</span>
        <button type="button" class="btn btn-primary opt-btn" @click="handleModifyNum('cateOffset', 1)">+</button>
      </div>

      <hr />
      <p>文件列表</p>
      <span>分类列表由上一步控制</span>
      <ul class="category">
        <li v-for="cate in cateList">
          <a href="javascript:void(0);" :class="{active: selectedCateID === cate.id}" @click="handleCateClick(cate.id, cate.name)">{{cate.name}}</a> |
        </li>
      </ul>
      <div class="upload-btn">
        <input type="file" accept="image/*" class="upload-input" @change="uploadFileUseCateName">
        <button type="button" class="btn btn-primary">上传文件（cate name）</button>
      </div>
      <div class="upload-btn">
        <input type="file" accept="image/*" class="upload-input" @change="uploadFileUseCateID">
        <button type="button" class="btn btn-primary">上传文件（cate id）</button>
      </div>
      <button type="button" class="btn btn-primary" :disabled="!selectedFileList.length" @click="handleDeleteSelectedFile">删除</button>
      <p>order_by:</p>
      <div style="margin-bottom: 10px;">
        <div class="form-check form-check-inline" v-for="sort in sortKeyList">
          <label class="form-check-label">
            <input class="form-check-input" type="radio" :value="sort.value" v-model="sortKey">
            {{sort.name}}
          </label>
        </div>
      </div>
      <p>limit:</p>
      <div style="margin-bottom: 10px;">
        <button type="button" class="btn btn-primary opt-btn" @click="handleModifyNum('limit', -1)">-</button>
        <span class="num">{{limit}}</span>
        <button type="button" class="btn btn-primary opt-btn" @click="handleModifyNum('limit', 1)">+</button>
      </div>
      <p>offset:</p>
      <div style="margin-bottom: 10px;">
        <button type="button" class="btn btn-primary opt-btn" @click="handleModifyNum('offset', -1)">-</button>
        <span class="num">{{offset}}</span>
        <button type="button" class="btn btn-primary opt-btn" @click="handleModifyNum('offset', 1)">+</button>
      </div>
      <ul class="list-group">
        <li key="item.id" v-for="item in fileList" class="list-group-item d-flex justify-content-between align-items-center">
          <input :value="item.id" type="checkbox" v-model="selectedFileList">
          <span>{{item.name}}</span>
          <a href="javascript:void(0);" style="float: right;" @click="deleteFileSigle(item.id)">删除</a>
        </li>
      </ul>
    </div>
  </div>

  <div class="card">
    <div class="card-body">
      <h5 class="card-title">获取文件详情</h5>
      <p v-if="fileList.length">record id = {{fileList[0].id}}</p>
      <p v-else>该分类下没有文件，请先上传一个文件</p>
      <button type="button" class="btn btn-primary" @click="getFileDetail" :disabled="!fileList.length">获取文件详情</button>
    </div>
  </div>

  <div class="card">
    <div class="card-body">
      <h5 class="card-title">文件分类</h5>
      <p v-if="cateList.length > 1">record id = {{cateList[1].id}}</p>
      <button type="button" class="btn btn-primary" @click="getFileCategoryDetail" :disabled="cateList.length <= 1">文件分类详情</button>
      <button type="button" class="btn btn-primary" @click="getFileListFromCategory" :disabled="cateList.length <= 1">获取文件分类下所有文件</button>
    </div>
  </div>
</div>

<script src="../utils/common.js"></script>
<script src="./index.js"></script>
</body>
</html>